
class site:
    def __init__(self, site_id, url, tci=0, external=False):
        self.site_id = site_id
        self.url = url
        self.tci = tci
        self.external = external
        self.table_name = 'sites'
    def __str__(self):
        prefix = ''
        if self.external:
            prefix = '# '
        return '%ssite %d at %s with %d tci' % \
               (prefix, self.site_id, self.url, self.tci)

class page:
    def __init__(self, page_id, site_id, url, depth, pr, text, external=False):
        self.page_id = page_id
        self.site_id = site_id
        self.url = url
        self.depth = depth
        self.pr = pr
        self.text = text
        self.external = external
        self.table_name = 'pages'
    def __str__(self):
        prefix = ''
        if self.external:
            prefix = '# '
        return '\t%spage %d at %s of site %d at depth %d, with pr %d' % \
               (prefix, self.page_id, self.url, \
                self.site_id, self.depth, self.pr)

class link:
    def __init__(self, link_id, page_id, title, text):
        self.link_id = link_id
        self.page_id = page_id
        self.title = title
        self.text = text
        self.table_name = 'links'
    def __str__(self):
        txt = self.title
        if not txt:
            txt = self.text
        return '\t\tlink %d to page %d, "%s"' % \
               (self.link_id, self.page_id, txt)

class keyword:
    def __init__(self, keyword_id, word, popularity=0):
        self.keyword_id = keyword_id
        self.word = word
        self.popularity = popularity
        self.table_name = 'keywords'
    def __str__(self):
        return '\t\tkeyword "%s" (id %d) with popularity %d' % \
               (self.word, self.keyword_id, self.popularity)

class page_to_link:
    def __init__(self, page_id, link_id, num_links):
        self.page_id = page_id
        self.link_id = link_id
        self.num_links = num_links
        self.table_name = 'page_to_link'
    def __str__(self):
        return '\t\tpage %d has %d links %d' % \
               (self.page_id, self.num_links, self.link_id)

class page_to_keyword:
    def __init__(self, page_id, keyword_id, relevance):
        self.page_id = page_id
        self.keyword_id = keyword_id
        self.relevance = relevance
        self.table_name = 'page_to_keyword'
    def __str__(self):
        return '\t\tpage %d has relevance %d with keyword %d' % \
               (self.page_id, self.relevance, self.keyword_id)

class link_to_keyword:
    def __init__(self, link_id, keyword_id, relevance):
        self.link_id = link_id
        self.keyword_id = keyword_id
        self.relevance = relevance
        self.table_name = 'link_to_keyword'
    def __str__(self):
        return '\t\tlink %d has relevance %d with keyword %d' % \
               (self.link_id, self.relevance, self.keyword_id)

